#!/usr/bin/env python 
# -*- coding:utf-8 -*-
'''
通过飞书推送运行情况
'''
from app.utils.feishu import FeiShu
from app.config import FeiShu as fesh
from app.schemes.Multithreading import *

class FeishuMessage():
    @staticmethod
    @FeishuThread
    def taskCreation(title: str, id: int = 1, explain: str = '', uuid: str = '', found: str = '', url: str = '',
                people: str = '', wordurl: str = '') -> bool:
        '''
        任务创建消息发送
        :param title:
        :param id:
        :param explain:
        :param uuid:
        :param found:
        :param url:
        :param people:
        :return: bool
        '''
        msg_text = '任务ID：{id}\n任务标题：{title}\n任务UUID：{uuid}\n任务创建者：{found}\n任务参与者：{people}\n任务说明：{explain}\n在线文档:{wordurl}\n'
        msg_text = msg_text.format(id=id, title=title, uuid=uuid, found=found, people=people, explain=explain,
                                   wordurl=wordurl)
        message = {
            "msg_type": "post",
            "content": {
                "post": {
                    "zh_cn": {
                        "title": "任务创建通知",
                        "content": [
                            [
                                {
                                    "tag": "text",
                                    "text": msg_text
                                },
                                {
                                    "tag": "a",
                                    "text": "点我即可查看",
                                    "href": url
                                }
                            ]
                        ]
                    }
                }
            }
        }
        fs = FeiShu(fesh.mine.WEBHOOK, fesh.mine.SECRET)
        try:
            status = fs.sendMessage(message=message, issecret=True)
        except Exception as err:
            status = {'status': False, 'message': str(err)}
        return status

    @staticmethod
    @FeishuThread
    def systemNotification(message):
        '''
        系统消息通知
        :param message:
        :return:
        '''
        fs = FeiShu(fesh.mine.WEBHOOK, fesh.mine.SECRET)
        try:
            status = fs.sendMessage(message=message, issecret=True)
        except Exception as err:
            status = {'status': False, 'message': str(err)}
        return status